﻿@model TruckingApplication.Dal.EntityModels.RESOURCE

@{
    ViewBag.Title = "Create";
}

<link href="@Url.Content("~/Content/jquery-ui.css")" rel="stylesheet" type="text/css" />

<h2>Create New User</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        var isBounceBack = false;
        //$('#startDate').datepicker();
        $('#resourceTypeID').change(function () {
            isBounceBack = false;
            $('select option:selected').each(function () {
                if (isBounceBack != false)
                    return;
                var resourceType = $(this).text();
                
                if (resourceType != "CARRIER") {
                    
                    // hide MC# field
                    $('#mcNumber').css('display', 'none');
                    $('#mcLabel').css('display', 'none');

                    // hide factoring fee
                    $('#factoringFee').css('display', 'none');
                    $('#factoringFeeLabel').css('display', 'none');

                    // hide Roadside assistance and Insurance div
                    $('#roadside_insurance').css('display', 'none');

                    // Hide fields to capture Trailer Information
                    $('#trailerInfo').css('display', 'none');

                    // display commission
                    $('#commission').css('display', 'block');
                    $('#commissionLabel').css('display', 'block');
                    if (isBounceBack == false) {
                        isBounceBack = true;
                    }
                } else {
                    if (isBounceBack != false)
                        return;
                    // display MC# field
                    $('#mcNumber').css('display', 'block');
                    $('#mcLabel').css('display', 'block');

                    // display factoring fee
                    $('#factoringFee').css('display', 'block');
                    $('#factoringFeeLabel').css('display', 'block');

                    // Display fields to capture Trailer Information
                    $('#trailerInfo').css('display', 'block');
                    // display Roadside assistance and Insurance div
                    $('#roadside_insurance').css('display', 'block');

                    // hide commission
                    $('#commission').css('display', 'none');
                    $('#commissionLabel').css('display', 'none');
                    if (isBounceBack == false) {
                        isBounceBack = true;
                    }
                }
            });
        });

        //$('#startDate').datepicker();
        //$('#tb_insStartDate').datepicker();
    });

    function enrollInsurance(val) {
        if (val == 'Yes') {
            $('#insuranceForm').css('display', 'block');
        } else {
            $('#insuranceForm').css('display', 'none');
        }
    }

    function calculateInsurancePaymentAmount() {
        // get length [26 weeks or 52 weeks]
        var weeks = 0;
        $('#ddl_insLgth select option:selected').each(function () {
            var lgth = $(this).text();
            alert(lgth);
            if (lgth != "6 Months") {
                weeks = 52;
            } else {
                weeks = 26;
            }
        });

        //alert(weeks);
        // get pay frequency (if not other) [weekly, bi-weekly, monthly, other]

            // if pay frequency is other, display text box and message advising user they must calculate manually
            // and tell the system because the system cannot decipher other

        // get total amount


    }

</script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <div id="lowerContainer">
		<div id="lowerContainerInner">
            <table id="tableMgmt" style="width: 100%;">
                <tr>
                    <td>
                        @Html.LabelFor(model => model.resourceTypeID, "Resource Type")
                    </td>   
                    <td>    
                        @*@Html.DropDownList("resourceTypeID", String.Empty)
                        @Html.ValidationMessageFor(model => model.resourceTypeID)*@
                        @(Html.Kendo()
                            .DropDownList()
                            .Name("resourceTypeID")
                            .BindTo(ViewBag.resourceTypeID as SelectList)
                            .HtmlAttributes(new { style = "width:200px" })
                        )
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.firstName)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.firstName)
                        @Html.ValidationMessageFor(model => model.firstName)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.lastName)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.lastName)
                        @Html.ValidationMessageFor(model => model.lastName)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.address)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.address)
                        @Html.ValidationMessageFor(model => model.address)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.city)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.city)
                        @Html.ValidationMessageFor(model => model.city)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.state)
                    </td>   
                    <td>    
                        @*@Html.DropDownList("States", "Select One")*@
                        @(Html.Kendo()
                            .DropDownList()
                            .Name("States")
                            .BindTo(ViewBag.States as SelectList)
                            .HtmlAttributes(new { style = "width:200px" })
                        )
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.zip)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.zip)
                        @Html.ValidationMessageFor(model => model.zip)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.startDate)
                    </td>   
                    <td>    
                        @(Html.Kendo().DatePickerFor(model => model.startDate).Name("startDate").HtmlAttributes(new { style = "width:200px" }))
                        @Html.ValidationMessageFor(model => model.startDate)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.ssNum)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.ssNum)
                        @Html.ValidationMessageFor(model => model.ssNum)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.taxID)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.taxID)
                        @Html.ValidationMessageFor(model => model.taxID)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.email)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.email)
                        @Html.ValidationMessageFor(model => model.email)
                    </td>     
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.phone)
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.phone)
                        @Html.ValidationMessageFor(model => model.phone)
                    </td>     
                </tr>
                <tr>
                    <td>
                        <div id="commissionLabel">
                            @Html.LabelFor(model => model.commission)
                        </div>
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.commission)
                        @Html.ValidationMessageFor(model => model.commission)
                    </td>     
                </tr>
                <tr>
                    <td>
                        <div id="factoringFeeLabel">
                            @Html.LabelFor(model => model.factoringFee)
                        </div>
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.factoringFee)
                        @Html.ValidationMessageFor(model => model.factoringFee)
                    </td>     
                </tr>
                <tr>
                    <td>
                        <div id="mcLabel">
                            @Html.LabelFor(model => model.mcNumber)
                        </div>
                    </td>   
                    <td>    
                        @Html.EditorFor(model => model.mcNumber)
                        @Html.ValidationMessageFor(model => model.mcNumber)
                    </td>     
                </tr>
                <tr id="trailerInfo" style="display:none;">
                    <td colspan="2">
                        <table>
                            <tr>
                                <td>
                                    Trailer Type
                                </td>
                                <td>
                                    @Html.DropDownList("trailerTypeID", String.Empty)
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Vin #
                                </td>
                                <td>
                                    @Html.TextBox("Vin")
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Miles
                                </td>
                                <td>
                                    @Html.TextBox("Miles")
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    Would you like to enroll this trailer for insurance?
                                    <input id="_rb_i_yes" type="radio" value="Yes" name="ins" onclick="enrollInsurance('Yes');"> Yes
                                    <input id="_rb_i_no" type="radio" value="No" name="ins"  onclick="enrollInsurance('No');"> No
                                    <div id="insuranceForm" style="display:none;">
                                        <table>
                                            <tr>
                                                <td>
                                                    Start Date:
                                                </td>
                                                <td>
                                                    <input type="text" id="tb_insStartDate" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    Length of insurance:
                                                </td>
                                                <td>
                                                    <select id="ddl_insLgth">
                                                        <option>6 Months</option>
                                                        <option>12 Months</option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    Total Payment Amount:
                                                </td>
                                                <td>
                                                    <input type="text" id="tb_totalPaymentAmt" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    Payment Frequency:
                                                </td>
                                                <td>
                                                    <select id="ddl_insFqcy">
                                                        <option>Weekly</option>
                                                        <option>Bi-Weekly</option>
                                                        <option>Monthly</option>
                                                        <option>Other</option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <a href="#" onclick="calculateInsurancePaymentAmount(); return false;">Calculate Payment Amount</a>
                                                    <br /><br />
                                                    <div id="insurancePaymentAmount"></div>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    Would you like to enroll in our roadside assistance program?
                                    <input id="_rb_ra_yes" type="radio" value="Yes" name="ra"> Yes
                                    <input id="_rb_ra_no" type="radio" value="No" name="ra"> No
                                </td>
                            </tr>
                        </table>
                    </td>
                    
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="Create" class="button default large" />

                        @Html.ActionLink("Cancel", "Dashboard", "Account", null, new { @class = "button cancel large", @style = "line-height:25px; width:70px;" })
                    </td>     
                </tr>
            </table>
        </div>
    </div>
}